<template>
  <div  v-if="showPage" class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="90px">
      <el-form-item label="姓名" prop="username">
        <el-input v-model="queryParams.username" placeholder="请输入姓名" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
 <el-table v-loading="loading" :data="manageList" @selection-change="handleSelectionChange">
  <el-table-column label="ID" align="center" prop="id" />
  <el-table-column label="姓名" align="center" prop="username" />
  <el-table-column label="工号" align="center" prop="jobNumber" />
  <el-table-column label="部门" align="center" prop="dept" />
  <el-table-column label="位置" align="center" prop="location" />
  <el-table-column label="方向" align="center" prop="direction" />
  <el-table-column label="状态" align="center" prop="status">
    <template slot-scope="scope">
      <el-tag :type="scope.row.status === 1 ? 'success' : 'danger'">
        {{ scope.row.status === 1 ? '成功' : '失败' }}
      </el-tag>
    </template>
  </el-table-column>
  <el-table-column label="设备ID" align="center" prop="deviceId" />
  <el-table-column label="创建时间" align="center" prop="createTime" width="180" />
 
</el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
  </div>
   <div v-else>
  <el-empty description="暂无权限"></el-empty>
  </div>
</template>

<script>
import {
  listManage,
  getManage,
  delManage,
  addManage,
  updateManage,
  controllist
} from "@/api/system/manage";

export default {
  name: "checkingin",
  data() {
    return {
          showPage:true,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // token表格数据
      manageList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
       username:''
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  created() {
      this.getShow()
    this.getList();
  },
  methods: {
       getShow(){
  const a = {
    pageNum: 1,
    pageSize: 10
  }
  listManage(a).then(res => {
    console.log(res.rows);
    const foundItem = res.rows.find(item => item.id === 53);
    if (foundItem) {
      this.showPage = foundItem.isAuth;
    }
  })
},
    formatBoolean(row, column) {
      return row.isAuth ? "是" : "否";
    },

    /** 查询token列表 */
    getList() {
      this.loading = true;
      controllist(this.queryParams).then((response) => {
        this.manageList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.queryParams = {
       pageNum: 1,
      pageSize: 10,
      username:''
      };
      // this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.reset("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加token";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getManage(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改token";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateManage(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addManage(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除token编号为"' + ids + '"的数据项？')
        .then(function () {
          return delManage(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/manage/export",
        {
          ...this.queryParams,
        },
        `manage_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
